Skip to main content

Logistic regression analysis

Logistic regression analyses (logit/probit) are used to estimate the effect a set of explanatory variables has on the probability of a given outcome given by a dichotomous response variable (job/non-job, action/no action etc). Through options, you can adapt the output (do not show the fixed term, change the significance level, etc.).

The example below demonstrates a logit analysis. Alternatively, probit can also be used. Multinomial analyses (more than 2 outcomes) can also be done using the command mlogit.

 //Connect to database
require no.ssb.fdb:33 as db

//Start by constructing population
create-dataset demographydata
import db/BEFOLKNING_FOEDSELS_AAR_MND as birth_year_month
import db/BEFOLKNING_STATUSKODE 2020-01-01 as regstat
generate age = 2020 - int(birth_year_month / 100)
keep if regstat == '1' & inrange(age,16,66)

//Importing relevant analysis variables
import db/BEFOLKNING_KJOENN as gender
import db/SIVSTANDFDT_SIVSTAND 2020-01-01 as civstat
import db/INNTEKT_BRUTTOFORM 2020-01-01 as wealth
import db/INNTEKT_WYRKINNT 2021-01-01 as work_income21

//Generate a dependent variable with two outcomes (dummy variable): High work_income vs. low work_income
generate high_income = work_income21 > 800000

//Adapt the independent variables so that they suit the statistical model (most variables needs to be transformed into dummy variables)
generate male = gender == '1'
generate married = civstat == '2'
generate wealth_high = wealth > 1500000

//Run the logit analysis where the dependent variable (dummy) is required to be listed first
logit high_income male married age wealth_high